use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2020\program\n82_4y_8417_renew.dta",clear
set more off 
mata: mata set matafavor speed, perm
tsset id period

egen free_a=mean(sc_right),   by(id)
egen fd_a=  mean(fin_dev),    by(id)
egen fs_a=  mean(fin_str),    by(id)
egen bon_a= mean(av_bon),     by(id)
egen ler_a= mean(av_lern),    by(id)
egen con_a= mean(lnav_concn), by(id)
egen hh_a=  mean(lnav_borhh), by(id)
egen fm_a=  mean(lnav_borfm), by(id)

tabstat free_a fd_a fs_a bon_a ler_a con_a hh_a fm_a, ///
stat(min p10 p25 p50 mean p75 p90 max)

**aggregate**

gen fd1_y=0 if id==27
replace fd1_y=0 if id==41
replace fd1_y=0 if id==12
replace fd1_y=0.0301  if id==13
replace fd1_y=-0.0234 if id==80
gen fd_1=0.5014 if id==27
replace fd_1=0.5570 if id==41
replace fd_1=0.6098 if id==12
replace fd_1=0.0038 if id==13
replace fd_1=1 if id==80

gen fs1_y=0 if id==74
replace fs1_y=0 if id==74
replace fs1_y=0 if id==63
replace fs1_y=0 if id==30
replace fs1_y=-0.0099 if id==13
replace fs1_y=0.0252 if id==80
gen fs_1=0.1739 if id==74
replace fs_1=0.2867 if id==63
replace fs_1=0.3792 if id==30
replace fs_1=0.0038 if id==13
replace fs_1=1 if id==80


xtabond2 lnav_co2pc c.fin_dev c.fin_dev#c.sc_right c.fin_str c.fin_str#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev, lag(1 1))                gmm(c.fin_dev#c.sc_right, lag(2 2) collapse) ///
gmm(c.fin_str, lag(2 2) orthogonal)     gmm(c.fin_str#c.sc_right, lag(2 2) collapse) ///
gmm(c.sc_right,lag(2 2) collapse) ///
gmm(c.lnav_gdp,lag(1 1))                gmm(c.lnav_gdp#c.lnav_gdp,lag(1 2)) ///  
iv(ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)
sum fin_dev fin_str sc_right lnav_gdp

/*FD
找x軸的轉折點
margins, dydx(c.fin_dev) at(sc_right=(0.50773 (0.00001) 0.50774))
margins, dydx(c.fin_dev) at(sc_right=(0.63223 (0.00001) 0.63224))
找不同分位下的邊際效果
margins, dydx(c.fin_dev) at(sc_right=0.0038)
margins, dydx(c.fin_dev) at(sc_right=0.0561)
margins, dydx(c.fin_dev) at(sc_right=0.1666)
margins, dydx(c.fin_dev) at(sc_right=0.4366)
margins, dydx(c.fin_dev) at(sc_right=0.9444)
margins, dydx(c.fin_dev) at(sc_right=1)
margins, dydx(c.fin_dev) at(sc_right=1)
margins, dydx(c.fin_dev) at(sc_right=0.5076)
*/

margins, dydx(c.fin_dev) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(a) Effect of findev on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ findev") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0301 0.0031 -0.0234, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.5642 0.6322 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fd1_y fd_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0301 0.0038  "CHN", place(ne) size(small)) ///
text (0 0.5077       , place(sw) size(small)) ///
text (0 0.5014  "GHA", place(sw) size(small)) ///
text (0 0.5642       , place(s)  size(small)) ///
text (0 0.5570  "LVA", place(s)  size(small)) ///
text (0 0.6322       , place(ne) size(small)) ///
text (0 0.6098  "CHL", place(ne) size(small)) ///
text (-0.0234 1 "USA", place(s)  size(small))


/*FS
找x軸的轉折點
margins, dydx(c.fin_str) at(sc_right=(0.17730 (0.00001) 0.17732))
margins, dydx(c.fin_str) at(sc_right=(0.38279 (0.00001) 0.38281))
找不同分位下的邊際效果
margins, dydx(c.fin_str) at(sc_right=0.0038)
margins, dydx(c.fin_str) at(sc_right=0.0561)
margins, dydx(c.fin_str) at(sc_right=0.1666)
margins, dydx(c.fin_str) at(sc_right=0.4366)
margins, dydx(c.fin_str) at(sc_right=0.9444)
margins, dydx(c.fin_str) at(sc_right=1)
margins, dydx(c.fin_str) at(sc_right=1)
margins, dydx(c.fin_str) at(sc_right=0.5076)
*/


margins, dydx(c.fin_str) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(d) Effect of finstr on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ finstr") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0099 0.0078 0.0252, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.1773 0.2861 0.3828 0.5076 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fs1_y fs_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0099  0.0038  "CHN", place(se) size(small)) ///
text (0.0078 0.5076  , place(se) size(small)) ///
text (0 0.1773       , place(nw) size(small)) ///
text (0 0.1739  "TUN", place(nw) size(small)) ///
text (0 0.2861       , place(se) size(small)) ///
text (0 0.2867  "ROU", place(se) size(small)) ///
text (0 0.3828       , place(se) size(small)) ///
text (0 0.3792  "IND", place(se) size(small)) ///
text (0.0252 1  "USA", place(wn) size(small))

**boone-BETTER**

gen bon1_y=0 if id==29
replace bon1_y=0 if id==60
replace bon1_y=0 if id==81
replace bon1_y=0.0762 if id==13
replace bon1_y=-0.0255 if id==80
gen bon_1=0.6792 if id==29
replace bon_1=0.7476 if id==60
replace bon_1=0.8360 if id==81
replace bon_1=0.0038  if id==13
replace bon_1=1 if id==80


xtabond2 lnav_co2pc c.fin_dev c.fin_dev#c.sc_right c.av_bon c.av_bon#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 4))               gmm(c.fin_dev#c.sc_right, lag(4 4)orthogonal) ///
gmm(c.av_bon,     lag(1 1)orthogonal)     gmm(c.av_bon#c.sc_right,  lag(3 6)collapse) ///
gmm(c.sc_right,   lag(1 1)collapse) ///
gmm(c.lnav_gdp,   lag(1 1))    gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 1) ) ///  
iv(ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)
sum fin_dev av_bon sc_right lnav_gdp

/*Boone
找x軸的轉折點
margins, dydx(c.av_bon) at(sc_right=(0.66840 (0.00001) 0.66843))
margins, dydx(c.av_bon) at(sc_right=(0.83619 (0.00001) 0.83621))
找不同分位下的邊際效果
margins, dydx(c.av_bon) at(sc_right=0.0038)
margins, dydx(c.av_bon) at(sc_right=0.0561)
margins, dydx(c.av_bon) at(sc_right=0.1666)
margins, dydx(c.av_bon) at(sc_right=0.4366)
margins, dydx(c.av_bon) at(sc_right=0.9444)
margins, dydx(c.av_bon) at(sc_right=1)
margins, dydx(c.av_bon) at(sc_right=1)
margins, dydx(c.av_bon) at(sc_right=0.5076)
*/

margins, dydx(c.av_bon) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(a) Effect of Boone on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ Boone") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0732 0.0248 -0.0255, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.6684 0.7502 0.8362 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter bon1_y bon_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0762  0.0038  "CHN", place(ne) size(small)) ///
text (0.0248  0.5076       , place(ne) size(small)) ///
text (0 0.6684       , place(sw) size(small)) ///
text (0 0.6792  "HUN", place(sw) size(small)) ///
text (0 0.7502       , place(ne) size(small)) ///
text (0 0.7476  "POL", place(ne) size(small)) ///
text (0 0.8362       , place(ne) size(small)) ///
text (0 0.8360  "URY", place(ne) size(small)) ///
text (-0.0255 1 "USA", place(s)  size(small))


/*
margins, dydx(c.fin_dev) at(sc_right=0.5024428)                                             
margins, dydx(c.fin_dev) at(sc_right=(0 (0.03) 1))             
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5024428, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ FD_aggregate") ///
xtitle("political rights", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))
*/

/**lerner**
xtabond2 lnav_co2pc c.fin_dev c.fin_dev#c.sc_right c.av_lern c.av_lern#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 1) orthogonal)    gmm(c.fin_dev#c.sc_right, lag(1 3) ) ///
gmm(c.av_lern,    lag(1 1) orthogonal)    gmm(c.av_lern#c.sc_right, lag(1 1) ) ///
gmm(c.sc_right,   lag(1 1) collapse) ///
gmm(c.lnav_gdp,   lag(1 1))  gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 1) ) ///  
iv(ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)
sum fin_dev av_lern sc_right lnav_gdp

margins, dydx(c.fin_dev) at(sc_right=0.5024428)                                             
margins, dydx(c.fin_dev) at(sc_right=(0 (0.005) 1))             
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5024428, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ FD_aggregate") ///
xtitle("political rights", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))

margins, dydx(c.av_lern) at(sc_right=0.5024428)
margins, dydx(c.av_lern) at(sc_right=(0 (0.005) 1)) 
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5024428, lcolor(red) lpattern(dash))  ///
ytitle("∂ CO2 / ∂ Lerner") ///
xtitle("political rights", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))
*/


**concerntration**

gen concn1_y=0 if id==60
replace concn1_y=0 if id==12
replace concn1_y=0.0640 if id==13
replace concn1_y=-0.0223 if id==80
gen concn_1=0.7476 if id==60
replace concn_1=0.6622 if id==12
replace concn_1=0.0038 if id==13
replace concn_1=1 if id==80


xtabond2 lnav_co2pc c.fin_dev c.fin_dev#c.sc_right c.lnav_concn c.lnav_concn#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(2 2))    gmm(c.fin_dev#c.sc_right,    lag(3 3) orthogonal) ///
gmm(c.lnav_concn, lag(1 4))    gmm(c.lnav_concn#c.sc_right, lag(1 1) orthogonal) ///
gmm(c.sc_right,   lag(1 3) collapse ) ///
gmm(c.lnav_gdp,   lag(1 1))    gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 1) orthogonal) ///  
iv(ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

/*concertration
找x軸的轉折點
margins, dydx(c.lnav_concn) at(sc_right=(0.63224 (0.00001) 0.63226))
找不同分位下的邊際效果
margins, dydx(c.lnav_concn) at(sc_right=0.0038)
margins, dydx(c.lnav_concn) at(sc_right=0.0561)
margins, dydx(c.lnav_concn) at(sc_right=0.1666)
margins, dydx(c.lnav_concn) at(sc_right=0.4366)
margins, dydx(c.lnav_concn) at(sc_right=0.9444)
margins, dydx(c.lnav_concn) at(sc_right=1)
margins, dydx(c.lnav_concn) at(sc_right=1)
margins, dydx(c.lnav_concn) at(sc_right=0.5076)
*/


margins, dydx(lnav_concn) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(d) Effect of concerntration on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ concerntration") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0640 0.0104 -0.0223, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.6323 0.7436 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter concn1_y concn_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0640  0.0038  "CHN", place(ne) size(small)) ///
text (0.0204  0.5076       , place(ne) size(small)) ///
text (0 0.6323       , place(ne) size(small)) ///
text (0 0.6622  "SVK", place(ne) size(small)) ///
text (0 0.7436       , place(ne) size(small)) ///
text (0 0.7476  "POL", place(ne) size(small)) ///
text (-0.0223 1 "USA", place(s)  size(small))

/*
margins, dydx(c.fin_dev) at(sc_right=0.5024428)                                             
margins, dydx(c.fin_dev) at(sc_right=(0 (0.005) 1))             
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5024428, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ FD_aggregate") ///
xtitle("political rights", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))
*/


use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2018\submit\version3_202007\Program\n82_4y_fin_202005.dta",clear
tsset id period

egen free_a=mean(sc_right),   by(id)
egen hh_a=  mean(lnav_borhh), by(id)
egen fm_a=  mean(lnav_borfm), by(id)

tabstat free_a hh_a fm_a, ///
stat(min p10 p25 p50 mean p75 p90 max)

*household & enterprise*

gen hh1_y=0 if id==20
replace hh1_y=0 if id==7
replace hh1_y=0 if id==67
replace hh1_y=0.0190 if id==13
replace hh1_y=-0.0317 if id==80
gen hh_1=0.3014 if id==20
replace hh_1=0.3784 if id==7
replace hh_1=0.4640 if id==67
replace hh_1=0.0038 if id==13
replace hh_1=1 if id==80

gen fm1_y=0 if id==10
replace fm1_y=0 if id==56
replace fm1_y=0 if id==60
replace fm1_y=-0.0406 if id==13
replace fm1_y=0.0360 if id==80
gen fm_1=0.4365 if id==10
replace fm_1=0.5354 if id==56
replace fm_1=0.7308 if id==60
replace fm_1=0.0038 if id==13
replace fm_1=1 if id==80

xtabond2 lnav_co2pc c.lnav_borhh c.lnav_borhh#c.sc_right c.lnav_borfm c.lnav_borfm#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.lnav_borhh, lag(1 2) )               gmm(c.lnav_borhh#c.sc_right, lag(2 2) orthogonal) ///
gmm(c.lnav_borfm, lag(2 2) )               gmm(c.lnav_borfm#c.sc_right, lag(2 2) collapse ) ///
gmm(c.sc_right,   lag(2 2)) ///
gmm(c.lnav_gdp,   lag(2 2)  orthogonal )   gmm(c.lnav_gdp#c.lnav_gdp,   lag(1 1)  ) ///  
iv(ln_co2pc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) twostep small
margins, dydx(c.lnav_gdp)
sum lnav_borhh lnav_borfm sc_right lnav_gdp

/*household credit
找x軸的轉折點
margins, dydx(c.lnav_borhh) at(sc_right=(0.30025 (0.00001) 0.30026))
margins, dydx(c.lnav_borhh) at(sc_right=(0.48120 (0.00001) 0.48121))
找不同分位下的邊際效果
margins, dydx(c.lnav_borhh) at(sc_right=0.0038)
margins, dydx(c.lnav_borhh) at(sc_right=0.0561)
margins, dydx(c.lnav_borhh) at(sc_right=0.1666)
margins, dydx(c.lnav_borhh) at(sc_right=0.4366)
margins, dydx(c.lnav_borhh) at(sc_right=0.9444)
margins, dydx(c.lnav_borhh) at(sc_right=1)
margins, dydx(c.lnav_borhh) at(sc_right=1)
margins, dydx(c.lnav_borhh) at(sc_right=0.5076)
*/


margins, dydx(lnav_borhh) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(a) Effect of household credit on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ household credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0190 -0.0067 -0.0317, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.3003 0.3780 0.4812 0.5076 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter hh1_y hh_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0190  0.0038  "CHN", place(ne) size(small)) ///
text (-0.0067 0.5076       , place(ne) size(small)) ///
text (0 0.3003       , place(sw) size(small)) ///
text (0 0.3014  "ECU", place(sw) size(small)) ///
text (0 0.3780       , place(ne) size(small)) ///
text (0 0.3784  "BOL", place(ne) size(small)) ///
text (0 0.4812       , place(ne) size(small)) ///
text (0 0.4640  "ZAF", place(ne) size(small)) ///
text (-0.0317 1 "USA", place(s)  size(small))

/*enterprise credit
找x軸的轉折點
margins, dydx(c.lnav_borfm) at(sc_right=(0.42680 (0.00001) 0.42683))
margins, dydx(c.lnav_borfm) at(sc_right=(0.73215 (0.00001) 0.73216))
找不同分位下的邊際效果
margins, dydx(c.lnav_borfm) at(sc_right=0.0038)
margins, dydx(c.lnav_borfm) at(sc_right=0.0561)
margins, dydx(c.lnav_borfm) at(sc_right=0.1666)
margins, dydx(c.lnav_borfm) at(sc_right=0.4366)
margins, dydx(c.lnav_borfm) at(sc_right=0.9444)
margins, dydx(c.lnav_borfm) at(sc_right=1)
margins, dydx(c.lnav_borfm) at(sc_right=1)
margins, dydx(c.lnav_borfm) at(sc_right=0.5076)
*/

margins, dydx(lnav_borfm) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(d) Effect of enterprise credit on CO2 emissions") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ CO2 / ∂ enterprise credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0406 -0.0018 0.0360, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.4268 0.5076 0.5319 0.7322 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fm1_y fm_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0406  0.0038  "CHN", place(se) size(small)) ///
text (-0.0018  0.5076       , place(se) size(small)) ///
text (0 0.4268       , place(nw) size(small)) ///
text (0 0.4365  "BGR", place(nw) size(small)) ///
text (0 0.5319       , place(n)  size(small)) ///
text (0 0.5354  "PAN", place(n)  size(small)) ///
text (0 0.7322       , place(se) size(small)) ///
text (0 0.7308  "POL", place(se) size(small)) ///
text (0.0360  1 "USA", place(n)  size(small))


